package cn.mooncode.basketballManage.service.impl;

import cn.mooncode.basketballManage.pojo.RespBean;
import cn.mooncode.basketballManage.pojo.RespPageBean;
import cn.mooncode.basketballManage.pojo.ScoreParam;
import cn.mooncode.basketballManage.service.IPlayerinfoService;
import cn.mooncode.basketballManage.mapper.PlayerinfoMapper;
import cn.mooncode.basketballManage.pojo.Playerinfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jwz
 * @since 2021-03-28
 */
@Service
public class PlayerinfoServiceImpl extends ServiceImpl<PlayerinfoMapper, Playerinfo> implements IPlayerinfoService {

    @Autowired
    private PlayerinfoMapper playerinfoMapper;

    /**
     * 获取所有球员信息
     * @param currentPage
     * @param size
     * @param playerinfo
     * @return
     */
    @Override
    public RespPageBean getAllPlayerInfo(Integer currentPage, Integer size, Playerinfo playerinfo) {
        Page<Playerinfo> page = new Page<>(currentPage, size);
        IPage<Playerinfo> playerinfoIPage = playerinfoMapper.getAllPlayerInfo(page, currentPage, size);
        return new RespPageBean(playerinfoIPage.getTotal(), playerinfoIPage.getRecords());
    }

    /**
     * 获取当前球员信息
     * @param id
     * @return
     */
    @Override
    public Playerinfo getCurrentPlayerInfo(Integer id) {
        return playerinfoMapper.getCurrentPlayerInfo(id);
    }

    /**
     * 修改球员成绩
     * @param scoreParam
     * @return
     */
    @Override
    public RespBean updateScores(ScoreParam scoreParam) {
        if (playerinfoMapper.updateScores(scoreParam)) {
            return RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败！");
    }

}
